package top.stmo.stmoBlog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.stmo.stmoBlog.dao.mapper.UserMapper;
import top.stmo.stmoBlog.dao.pojo.User;
import top.stmo.stmoBlog.dao.vo.UserVo;
import top.stmo.stmoBlog.service.UserService;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public UserVo findUserById(Long userId) {

        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.select(User::getId,User::getAvatar,User::getNickname);
        queryWrapper.eq(User::getId,userId);
        User user = userMapper.selectOne(queryWrapper);
        if(user == null) {
            user = new User();
            user.setId(1L);
            user.setNickname("梦长安");
            user.setAvatar("https://cn.bing.com/images/search?q=%e5%a4%b4%e5%83%8f&id=B1DB7D5FD9E071DA0F8084872BC011C4AB7D1A29&FORM=IQFRBA");
        }
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(user,userVo);
        return userVo;
    }
}
